package com.siruier.boss.ui.activity.task

import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.flyco.tablayout.listener.OnTabSelectListener
import com.siruier.boss.BuildConfig
import com.siruier.boss.R
import com.siruier.boss.databinding.ActivityTaskProfitBinding
import com.siruier.boss.ui.base.BaseActivity
import com.siruier.boss.ui.fragment.AdVideoTaskFragment
import com.siruier.boss.ui.fragment.CpaAsoFragment
import com.siruier.boss.ui.helper.InjectBundle
import com.siruier.boss.ui.utils.FragmentChangeManager

/**
 * 任务赚
 */
class TaskProfitActivity : BaseActivity<ActivityTaskProfitBinding>(), OnTabSelectListener {
    private val index: Int by InjectBundle { 0 }
    private var mFragmentChangeManager: FragmentChangeManager? = null

    override fun initView() {
        val fragments: ArrayList<Fragment>
        if (BuildConfig.MARKET) {
            vb.titleView.titleStr = "视频赚"
            vb.tabSegment.isVisible = false
            fragments = ArrayList()
            fragments.add(AdVideoTaskFragment())
            vb.tabSegment.currentTab = 0
        } else {
            vb.tabSegment.setTabData(arrayOf("任务赚", "视频赚"))
            fragments = ArrayList()
            fragments.add(CpaAsoFragment())
            fragments.add(AdVideoTaskFragment())
            vb.tabSegment.currentTab = index
        }
        vb.tabSegment.setOnTabSelectListener(com.siruier.boss.ui.listener.OnTabSelectListener {
            mFragmentChangeManager?.setFragments(it)
        })
        mFragmentChangeManager = FragmentChangeManager(supportFragmentManager, R.id.frameLayout, fragments, index)
    }

    override fun onTabSelect(position: Int) {
        mFragmentChangeManager?.setFragments(position)
    }

    override fun onTabReselect(position: Int) {

    }
}